package com.goldcn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * SwaggerConfig
 */
@Configuration
@EnableSwagger2
//@Profile("test")
public class SwaggerConfig {

    /**
     * 默认扫描包
     */
    private static final String SWAGGER_SCAN_BASE_PACKAGE="com.goldcn";
    private static final String SWAGGER_VERSION="1.0.0";


    @Bean
    public Docket Api() {
/*        return new Docket(DocumentationType.SWAGGER_2)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
              *//*  .paths(or(regex("/customClassify.*"),regex("/goodsInfo.*//**//*.*"),regex("/productInfo.*//**//*.*"),regex("/orderCart.*"),regex("/orderInfo.*"),
                        regex("/goodlabel.*"),regex("/goodlabel.*"),regex("/purchaseinfo.*"),regex("/purchaseproduct.*"),regex("/purchaseQuote.*"),
                        regex("/main.*"),regex("/factoryshow.*"),regex("/homepage.*")))//过滤的接口*//*
                .build()
                .apiInfo(ApiInfo());*/

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //扫描包路径
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }
/*    private ApiInfo ApiInfo() {
        ApiInfo apiInfo = new ApiInfo("银行服务基础接口",//大标题
                "银行服务基础接口",//小标题
                "1.0",//版本
                "b2b terms of service",
                "谢劲松(商品、购物车)、肖平(订单，统计)",//作者
                "网站链接",//链接显示文字
                "http://b2b.gcn99.com/dist/view/login.html"//网站链接
        );
        return apiInfo;
    }*/

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("基础接口")
                .description("基础接口")
                .license("")
                .licenseUrl("http://")
                .termsOfServiceUrl("")
                .version(SWAGGER_VERSION)
                .contact(new Contact("ldzb","",""))
                .build();
    }

}
